package sol.leetcode;

/**
 * Search a 2D Matrix II
 */
public class Issue240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length, n = matrix[0].length;

        int i = 0, j = n - 1;
        while (i < m && j >= 0) {
            if (matrix[i][j] == target)
                return true;
            else if (target < matrix[i][j])
                --j;
            else
                ++i;
        }
        return false;
    }


    public static void main(String[] args) {
        int[][] matrix = {{5}};
        System.out.println(new Issue240().searchMatrix(matrix, 5));
    }
}
